/**
 * @Classname org.tale.mscp.notify.controller.RecordNotifyController
 * @Description TODO
 * @author Tale-Mi
 * @date 2019/3/12 23:36
 */
package org.tale.mscp.notify.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tale.mscp.notify.entity.BrushCard;
import org.tale.mscp.notify.entity.CommonJsonFormat;
import org.tale.mscp.notify.services.IRecordNotifyService;
import org.tale.mscp.notify.utils.GsonUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.List;

@RestController
@RequestMapping(value = "/kqnotify")
public class RecordNotifyController {
    @Autowired
    public IRecordNotifyService recordNotifyService;

    /**
     * 中控考勤视图查询接口
     *
     * @param name
     * @param stdate
     * @return
     */
    @RequestMapping("/getPersonApi")
    public String getPersonApi(String name, String stdate) {
        CommonJsonFormat commonJsonFormat = new CommonJsonFormat();
        try {
            DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate startDate = LocalDate.parse(stdate);
            LocalDate endDate = startDate.with(TemporalAdjusters.lastDayOfMonth());
            List<BrushCard> brushCardList = recordNotifyService.getZhongkongRecord(startDate, endDate, name, null);
            commonJsonFormat.setResult(CommonJsonFormat.ResultEnum.success);
            commonJsonFormat.setResultDesc("正确返回");
            commonJsonFormat.setJsonContent(brushCardList);
        } catch (Exception e) {
            commonJsonFormat.setResult(CommonJsonFormat.ResultEnum.fail);
            commonJsonFormat.setResultDesc("系统错误:" + e.getMessage());
        } finally {
            return GsonUtils.gsonLocalDate.toJson(commonJsonFormat);
        }
    }
}
